package com.xinmao.quantitative.trad.backtesting;

import org.ta4j.core.BarSeries;
import org.ta4j.core.Indicator;
import org.ta4j.core.Rule;
import org.ta4j.core.indicators.RSIIndicator;
import org.ta4j.core.indicators.helpers.ClosePriceIndicator;
import org.ta4j.core.num.Num;
import org.ta4j.core.rules.OverIndicatorRule;
import org.ta4j.core.rules.UnderIndicatorRule;

public class RSIBackTest {

    public static Rule createEntryRule(BarSeries series, int shortBarCount, int longBarCount) {

        Indicator<Num> closePrice = new ClosePriceIndicator(series);
        RSIIndicator rsiIndicatorShort = new RSIIndicator(closePrice, shortBarCount);
        RSIIndicator rsiIndicatorLong = new RSIIndicator(closePrice, longBarCount);

        return  new UnderIndicatorRule(rsiIndicatorShort, 30)
                        .and(new OverIndicatorRule(rsiIndicatorLong, 70));
    }

    public static Rule createExitRule(BarSeries series, int shortBarCount, int longBarCount) {

        Indicator<Num> closePrice = new ClosePriceIndicator(series);
        RSIIndicator rsiIndicatorShort = new RSIIndicator(closePrice, shortBarCount);
        RSIIndicator rsiIndicatorLong = new RSIIndicator(closePrice, longBarCount);

        return  new OverIndicatorRule(rsiIndicatorShort, 70)
                        .and(new UnderIndicatorRule(rsiIndicatorLong, 30));
    }

}
